﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    //销售出库
    public class sal_SalesOutService : sal_SalesOutIService
    {
        private readonly MyDbContext MyDbContext;
        public sal_SalesOutService(MyDbContext myDb)
        {
            this.MyDbContext = myDb;
        }

        public Task<int> Add(sal_sales_Out sal_Sales_Out)
        {
            MyDbContext.sal_sales_Out.Add(sal_Sales_Out);
            return MyDbContext.SaveChangesAsync();
        }

        public Task<int> Add_C(sal_sales_Out_C data)
        {
            MyDbContext.sal_sales_Out_C.Add(data);
            return MyDbContext.SaveChangesAsync();
        }

        public async Task<int> Delete(int out_id)
        {
            var del = MyDbContext.sal_sales_Out.Find(out_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        public async Task<int> Delete_C(int OutID)
        {
            var del = MyDbContext.sal_sales_Out_C.Find(OutID);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        public Task<List<sal_sales_Out>> Query()
        {
            return MyDbContext.sal_sales_Out.Where(s => s.IsDeleted == false).ToListAsync();
        }

      

        public Task<int> Update(sal_sales_Out sal_Sales_Out)
        {
            MyDbContext.sal_sales_Out.Update(sal_Sales_Out);
            return MyDbContext.SaveChangesAsync();
        }

        public Task<int> Update_C(sal_sales_Out_C data)
        {
            MyDbContext.sal_sales_Out_C.Update(data);
            return MyDbContext.SaveChangesAsync();
        }
    }
}
